From de508d16cbabc4877ff205887b083644e1a36bc3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Fri, 26 Aug 2005 13:49:36 +0000 Subject: [PATCH] added type and component shuffling --- ChangeLog | 8 ++ babl/babl-fish.c | 195 +++++++++++++++++++++++++++-------------- tests/srgb_to_lab_u8.c | 6 +- 3 files changed, 139 insertions(+), 70 deletions(-) diff --git a/ChangeLog b/ChangeLog index d116a9b..6e5142c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-08-25 Øyvind Kolås + + * babl/babl-fish.c: + (babl_to_double),(babl_from_double): new functions. + (babl_fish_reference_process): made type a component + shuffling work for linear buffers + * tests/rgb_to_lab_u8.c: filled in calculated values. + 2005-08-25 Øyvind Kolås * tests/rgb_to_ycbcr.c, diff --git a/babl/babl-fish.c b/babl/babl-fish.c index ffb61a8..9dff7b1 100644 --- a/babl/babl-fish.c +++ b/babl/babl-fish.c @@ -26,6 +26,7 @@ #include "babl-type.h" #include "babl-model.h" #include "babl-image.h" +#include "babl-component.h" #include "babl-pixel-format.h" static int @@ -192,6 +193,118 @@ babl_fish (void *source, return babl_fish_reference_new (source_format, destination_format); } + +static void +convert_to_double (BablFormat *source_fmt, + BablImage *source, + void *source_buf, + void *source_double_buf, + int n) +{ + int i; + + BablImage *src_img; + BablImage *dst_img; + + src_img = (BablImage*) babl_image ( + babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL); + dst_img = (BablImage*) babl_image ( + babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL); + + dst_img->type[0] = (BablType*) babl_type_id (BABL_DOUBLE); + dst_img->pitch[0] = + (dst_img->type[0]->bits/8) * source_fmt->model->components; + dst_img->stride[0] = 0; + + + src_img->data[0] = source_buf; + src_img->type[0] = (BablType*) babl_type_id (BABL_DOUBLE); + src_img->pitch[0] = source_fmt->bytes_per_pixel; + src_img->stride[0] = 0; + + /* i is source position */ + for (i=0 ; icomponents; i++) + { + int j; + + src_img->type[0] = source_fmt->type[i]; + /* j is source position */ + for (j=0;jmodel->components;j++) + { + if (source_fmt->component[i] == + source_fmt->model->component[j]) + { + dst_img->data[0] = + source_double_buf + (dst_img->type[0]->bits/8) * j; + break; + } + } + + babl_conversion_process ( + babl_conversion_find (src_img->type[0], dst_img->type[0]), + src_img, dst_img, + n); + src_img->data[0] += src_img->type[0]->bits/8; + } + babl_free (src_img); + babl_free (dst_img); +} + + +static void +convert_from_double (BablFormat *destination_fmt, + void *destination_double_buf, + BablImage *destination, + void *destination_buf, + int n) +{ + int i; + + BablImage *src_img; + BablImage *dst_img; + + src_img = (BablImage*) babl_image ( + babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL); + dst_img = (BablImage*) babl_image ( + babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL); + + src_img->type[0] = (BablType*) babl_type_id (BABL_DOUBLE); + src_img->pitch[0] = + (src_img->type[0]->bits/8) * destination_fmt->model->components; + src_img->stride[0] = 0; + + dst_img->data[0] = destination_buf; + dst_img->type[0] = (BablType*) babl_type_id (BABL_DOUBLE); + dst_img->pitch[0] = destination_fmt->bytes_per_pixel; + dst_img->stride = 0; + + for (i=0 ; icomponents; i++) + { + int j; + + dst_img->type[0] = destination_fmt->type[i]; + + for (j=0;jmodel->components;j++) + { + if (destination_fmt->component[i] == + destination_fmt->model->component[j]) + { + src_img->data[0] = + destination_double_buf + (src_img->type[0]->bits/8) * j; + break; + } + } + + babl_conversion_process ( + babl_conversion_find (src_img->type[0], dst_img->type[0]), + src_img, dst_img, + n); + dst_img->data[0] += dst_img->type[0]->bits/8; + } + babl_free (src_img); + babl_free (dst_img); +} + static int babl_fish_reference_process (Babl *babl, BablImage *source, @@ -225,65 +338,17 @@ babl_fish_reference_process (Babl *babl, if (BABL_IS_BABL (source) || BABL_IS_BABL (destination)) { - babl_log ("%s(%p, %p, %p, %li): not handling BablImage yet", + babl_log ("%s(%p, %p, %p, %li): trying to handle BablImage (unconfirmed code)", __FUNCTION__, babl_fish, source, destination, n); - return -1; } -#if 0 /* draft code*/ - { - int i; - BablFormat *source_fmt = (BablFormat*)BABL(babl->fish.source); - BablFormat *destination_fmt = (BablFormat*)BABL(babl->fish.destination); - - BablImage *src_img = babl_image ("R", pr, 1, 0, NULL); - BablImage *dst_img = babl_image ("R", pr, 1, 0, NULL); - - for (i=0 ; i< destination_fmt->components; i++) - { - int j; - - dst_img->type[0] = destination_fmt->type[i]; - dst_img->pitch[0] = destination_fmt->pitch[i]; - dst_img->stride[0] = destination_fmt->stride[i]; - dst_img->data[0] = destination_fmt->data[i]; - - for (j=0;jcomponents;j++) - { - if (source_fmt->component[j] == destination_fmt[i]) - { - src_img->type[0] = source_fmt->type[j]; - src_img->pitch[0] = source_fmt->pitch[j]; - src_img->stride[0] = source_fmt->stride[j]; - src_img->data[0] = source_fmt->data[j]; - break; - } - babl_log ("%s(): matching source component not found", __FUNCTION); - } - - babl_conversion_process ( - babl_conversion_find ( - src_img->type[0], - dst_img->type[0] - /*babl_type_id (BABL_DOUBLE)*/ - ), - source, source_double_buf, - n); - } - } -#endif -#if 1 - babl_conversion_process ( - babl_conversion_find ( - BABL(babl->fish.source)->format.type[0], - babl_type_id (BABL_DOUBLE) - ), - source, source_double_buf, - n * BABL(babl->fish.source)->format.components); -#endif - - /* calculate planar representation of source_double, and rgba_double_buf */ - /* transform source_double_buf into rgba_double_buf rgba_double_buf is rgba double */ + convert_to_double ( + (BablFormat*) BABL(babl->fish.source), + BABL_IS_BABL(source)?source:NULL, + BABL_IS_BABL(source)?NULL:source, + source_double_buf, + n + ); babl_conversion_process ( babl_conversion_find ( @@ -293,9 +358,6 @@ babl_fish_reference_process (Babl *babl, source_image, rgba_image, n); - /* calculate planar representation of destination_double_buf */ - /* transform rgba_double_buf into destination_double_buf destination_double_buf is ???? double */ - babl_conversion_process ( babl_conversion_find ( babl_model_id (BABL_RGBA), @@ -304,14 +366,13 @@ babl_fish_reference_process (Babl *babl, rgba_image, destination_image, n); - /* FIXME: working directly on linear buffers */ - babl_conversion_process ( - babl_conversion_find ( - babl_type_id (BABL_DOUBLE), - BABL(babl->fish.destination)->format.type[0] - ), - destination_double_buf, destination, - n * BABL(babl->fish.destination)->format.components); + convert_from_double ( + (BablFormat*) BABL(babl->fish.destination), + destination_double_buf, + BABL_IS_BABL(destination)?destination:NULL, + BABL_IS_BABL(destination)?NULL:destination, + n + ); babl_free (source_image); babl_free (rgba_image); diff --git a/tests/srgb_to_lab_u8.c b/tests/srgb_to_lab_u8.c index 83c1a90..1e2b4e2 100644 --- a/tests/srgb_to_lab_u8.c +++ b/tests/srgb_to_lab_u8.c @@ -36,9 +36,9 @@ unsigned char reference_buf [PIXELS*3]= { 0, 128, 128, 135, 128, 128, 255, 128, 128, - 0, 0, 0, - 0, 0, 0, - 0, 0, 0}; + 135, 208, 195, + 223, 41, 211, + 82, 207, 20}; unsigned char destination_buf [PIXELS*3]; -- 2.30.2